import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    name: '登录',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard/index',
    children: [{
      path: '/dashboard/index',
      component: () => import('@/views/dashboard'),
      meta: {
        title: '首页',
        icon: 'dashboard'
      }
    }]
  },
  {
    path: '/banner',
    component: Layout,
    redirect: '/banner/Index',
    name: 'Banner',
    meta: {
      title: 'Banner',
      icon: 'el-icon-s-order'
    },
    children: [{
      path: 'Index',
      name: '轮播图',
      component: () => import('@/views/banner/Index'),
      meta: {
        title: 'Banner',
        icon: 'el-icon-document'
      }
    }]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/product/Index',
    name: '商品',
    meta: {
      title: '商品',
      icon: 'el-icon-truck'
    },
    children: [{
      path: 'index',
      name: '商品管理',
      component: () => import('@/views/product/Index'),
      meta: {
        title: '商品管理',
        icon: 'el-icon-truck'
      }
    }, {
      path: 'category',
      name: '商品分组',
      component: () => import('@/views/product/Category'),
      meta: {
        title: '商品分组',
        icon: 'el-icon-document-delete'
      }
    }, {
      path: 'attrGroup',
      name: '商品规格',
      component: () => import('@/views/product/AttrGroup'),
      meta: {
        title: '商品规格',
        icon: 'el-icon-document-delete'
      }
    }]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/Index',
    name: '订单',
    meta: {
      title: '订单',
      icon: 'el-icon-ship'
    },
    children: [{
      path: 'Index',
      name: '订单管理',
      component: () => import('@/views/order/Index'),
      meta: {
        title: '订单管理',
        icon: 'el-icon-ship'
      }
    }, {
      path: 'Refund',
      name: '退款管理',
      component: () => import('@/views/order/Refund'),
      meta: {
        title: '退款管理',
        icon: 'el-icon-tickets'
      }
    }, {
      path: 'Evaluation',
      name: '评价管理',
      component: () => import('@/views/order/Evaluation'),
      meta: {
        title: '评价管理',
        icon: 'el-icon-tickets'
      }
    }, {
      path: 'Ship',
      name: '发货管理',
      component: () => import('@/views/order/Ship'),
      meta: {
        title: '发货管理',
        icon: 'el-icon-tickets'
      }
    }, {
      path: 'AfterSales',
      name: '售后管理',
      component: () => import('@/views/order/AfterSales'),
      meta: {
        title: '售后管理',
        icon: 'el-icon-tickets'
      }
    }, {
      path: 'Delivery',
      name: '配送管理',
      component: () => import('@/views/order/Delivery'),
      meta: {
        title: '配送管理',
        icon: 'el-icon-tickets'
      }
    }, {
      path: 'Map',
      name: '快递费用管理',
      component: () => import('@/views/order/Map'),
      meta: {
        title: '快递费用管理',
        icon: 'el-icon-tickets'
      }
    }]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/Index',
    name: '文章',
    meta: {
      title: '文章',
      icon: 'el-icon-s-order'
    },
    children: [{
      path: 'Index',
      name: '文章管理',
      component: () => import('@/views/article/Index'),
      meta: {
        title: '文章管理',
        icon: 'el-icon-document'
      }
    }]
  },
  {
    path: '/marketing',
    component: Layout,
    // redirect: '/marketing/Index',
    name: '营销',
    meta: {
      title: '营销',
      icon: 'el-icon-s-order'
    },
    children: [{
      path: 'Discount',
      name: '折扣管理',
      component: () => import('@/views/marketing/Discount'),
      meta: {
        title: '折扣管理',
        icon: 'el-icon-document'
      }
    },
    {
      path: 'Coupon',
      name: '优惠券',
      component: () => import('@/views/marketing/Coupon'),
      meta: {
        title: '优惠券管理',
        icon: 'el-icon-document'
      }
    },
    {
      path: 'Spike',
      name: '秒杀管理',
      component: () => import('@/views/marketing/Spike'),
      meta: {
        title: '秒杀管理',
        icon: 'el-icon-document'
      }
    },
    {
      path: 'Group',
      name: '拼团管理',
      component: () => import('@/views/marketing/Group'),
      meta: {
        title: '拼团管理',
        icon: 'el-icon-document'
      }
    }]
  },
  // {
  //   path: '/coupon',
  //   component: Layout,
  //   // redirect: '/marketing/Index',
  //   name: '优惠券',
  //   meta: {
  //     title: '优惠券',
  //     icon: 'el-icon-s-order'
  //   },
  //   children: [{
  //     path: 'Index',
  //     name: '优惠券',
  //     component: () => import('@/views/coupon/Index'),
  //     meta: {
  //       title: '优惠券',
  //       icon: 'el-icon-document'
  //     }
  //   },
  //   {
  //     path: 'User',
  //     name: '用户优惠券管理',
  //     component: () => import('@/views/coupon/User'),
  //     meta: {
  //       title: '用户优惠券管理',
  //       icon: 'el-icon-document'
  //     }
  //   },
  //   {
  //     path: 'Record',
  //     name: '用户优惠券记录管理',
  //     component: () => import('@/views/coupon/Record'),
  //     meta: {
  //       title: '用户优惠券记录管理',
  //       icon: 'el-icon-document'
  //     }
  //   }]
  // },
  {
    path: '/media',
    component: Layout,
    redirect: '/media/Index',
    name: '媒体资源',
    meta: {
      title: '媒体资源',
      icon: 'el-icon-film'
    },
    children: [{
      path: 'Group',
      name: '媒体资源分组',
      component: () => import('@/views/media/Group'),
      meta: {
        title: '媒体资源分组',
        icon: 'el-icon-video-camera'
      }
    },
    {
      path: 'Index',
      name: '媒体资源列表',
      component: () => import('@/views/media/Index'),
      meta: {
        title: '媒体资源列表',
        icon: 'el-icon-video-camera'
      }
    }]
  },
  // {
  //   path: '/statistics',
  //   component: Layout,
  //   redirect: '/statistics/Index',
  //   name: '统计',
  //   meta: {
  //     title: '统计',
  //     icon: 'el-icon-s-order'
  //   },
  //   children: [{
  //     path: 'users',
  //     name: '用户统计',
  //     component: () => import('@/views/statistics/Users'),
  //     meta: {
  //       title: '用户统计',
  //       icon: 'el-icon-tickets'
  //     }
  //   }, {
  //     path: 'goods',
  //     name: '商品统计',
  //     component: () => import('@/views/statistics/Goods'),
  //     meta: {
  //       title: '商品统计',
  //       icon: 'el-icon-tickets'
  //     }
  //   }, {
  //     path: 'order',
  //     name: '订单统计',
  //     component: () => import('@/views/statistics/Order'),
  //     meta: {
  //       title: '订单统计',
  //       icon: 'el-icon-tickets'
  //     }
  //   }]
  // },

  //
  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [{
  //     path: 'menu1',
  //     component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //     name: 'Menu1',
  //     meta: {
  //       title: 'Menu1'
  //     },
  //     children: [{
  //       path: 'menu1-1',
  //       component: () => import('@/views/nested/menu1/menu1-1'),
  //       name: 'Menu1-1',
  //       meta: {
  //         title: 'Menu1-1'
  //       }
  //     },
  //       {
  //         path: 'menu1-2',
  //         component: () => import('@/views/nested/menu1/menu1-2'),
  //         name: 'Menu1-2',
  //         meta: {
  //           title: 'Menu1-2'
  //         },
  //         children: [{
  //           path: 'menu1-2-1',
  //           component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //           name: 'Menu1-2-1',
  //           meta: {
  //             title: 'Menu1-2-1'
  //           }
  //         },
  //           {
  //             path: 'menu1-2-2',
  //             component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //             name: 'Menu1-2-2',
  //             meta: {
  //               title: 'Menu1-2-2'
  //             }
  //           }
  //         ]
  //       },
  //       {
  //         path: 'menu1-3',
  //         component: () => import('@/views/nested/menu1/menu1-3'),
  //         name: 'Menu1-3',
  //         meta: {
  //           title: 'Menu1-3'
  //         }
  //       }
  //     ]
  //   },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: {
  //         title: 'menu2'
  //       }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    meta: {
      title: '用户',
      icon: 'el-icon-user',
      roles: ['管理员']
    },
    children: [{
      path: '/user/index',
      name: '用户列表',
      component: () => import('@/views/users/Index'),
      meta: {
        title: '用户列表',
        icon: 'el-icon-user'
      }
    },
    {
      path: '/user/brokerage',
      name: '佣金列表',
      component: () => import('@/views/users/Brokerage'),
      meta: {
        title: '佣金列表',
        icon: 'el-icon-user'
      }
    }]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/groupmenus',
    name: '系统',
    meta: {
      title: '系统',
      role: ['管理员'],
      icon: 'el-icon-s-tools'
    },
    children: [{
      path: '管理员列表',
      name: '管理员列表',
      component: () => import('@/views/system/Admin'),
      meta: {
        title: '管理员列表',
        icon: 'el-icon-lock'
      }
    },
    {
      path: 'groupmenus',
      name: '权限设置',
      component: () => import('@/views/system/GroupRole'),
      meta: {
        title: '权限设置',
        icon: 'el-icon-lock'
      }
    },
    {
      path: 'backup',
      name: '数据备份',
      component: () => import('@/views/system/Backup'),
      meta: {
        title: '数据备份',
        icon: 'el-icon-s-cooperation'
      }
    },
    {
      path: 'log',
      name: '日志',
      component: () => import('@/views/system/Log'),
      meta: {
        title: '日志',
        icon: 'el-icon-notebook-2'
      }
    },
    {
      path: 'sms',
      name: '短信',
      component: () => import('@/views/system/Sms'),
      meta: {
        title: '短信',
        icon: 'el-icon-mobile'
      }
    }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [{
      path: 'https://liguoqin.com',
      meta: {
        title: 'Blog',
        icon: 'link',
        roles: ['管理员']
      }
    }]
  }
  /** when your routing map is too long, you can split it into small modules **/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  // tableRouter,
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
